/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package documentadorrepositorio.apresentacao;

import documentadorrepositorio.interfaceGrafica.CarregandoDadosIG;
import documentadorrepositorio.repositorio.AnalisadorRepositorio;
import documentadorrepositorio.repositorio.GerenciadorRepositorioSVN;
import documentadorrepositorio.repositorio.IGerenciadorRepositorio;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JOptionPane;

/**
 *
 * @author DEP
 */
public class CarregandoDadosApresentacao {
    private CarregandoDadosIG frame;

    private AnalisadorRepositorio analisadorRepositorio = null;
    private IGerenciadorRepositorio _gerenciadorRepositorio = null;
    private Thread thr = null;
    
    public CarregandoDadosApresentacao(IGerenciadorRepositorio gerenciadorRepositorio) 
    {
        this._gerenciadorRepositorio = gerenciadorRepositorio;
        frame = new CarregandoDadosIG(null, true);
        frame.setLocationRelativeTo(null);
        adicionaListeners();
        thr = new Thread(new Runnable() {

            @Override
            public void run() {
                try
                {
                    analisadorRepositorio = new AnalisadorRepositorio(_gerenciadorRepositorio);
                    analisadorRepositorio.AnalisaRepositorio();
                    finalizaAnalise();
                }
                catch(Exception ex)
                {
                    JOptionPane.showMessageDialog(frame, ex.getMessage(),"Documentador de Repositório",JOptionPane.OK_OPTION);
                }
            }
        });
        this.frame.setVisible(true);
    }

    private void finalizaAnalise()
    {
        this.frame.setVisible(false);
        PrincipalIGApresentacao principal = new PrincipalIGApresentacao(_gerenciadorRepositorio, analisadorRepositorio);
    }
    
    private void adicionaListeners() {
        this.frame.addWindowListener(new WindowListener() {

            @Override
            public void windowOpened(WindowEvent e) {
                frame.getBarraProgresso().setIndeterminate(true);
                thr.start();
            }

            @Override
            public void windowClosing(WindowEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void windowClosed(WindowEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void windowIconified(WindowEvent e) {
               // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void windowDeiconified(WindowEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void windowActivated(WindowEvent e) {
               // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void windowDeactivated(WindowEvent e) {
             //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
    }
    
   
    
}
